<{include file="public_html/header.html"}>
<{include file="public_html/left_menu.html"}>

<blockquote class="layui-elem-quote"><{$action}></blockquote>

<form class="layui-form layui-form-pane" method="post" >
	<input type="hidden" name="id" value="<{$agent_info['id']|default:'0'}>" />
	<div class="layui-form-item">
		<label class="layui-form-label">代理商名称</label>
		<div class="layui-input-block">
			<input type="text" name="name" value="<{$agent_info.name|default:''}>" lay-verify="title" autocomplete="off" class="layui-input">
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">联系电话</label>
		<div class="layui-input-block">
			<input type="text" name="phone" value="<{$agent_info.phone|default:''}>" lay-verify="required" autocomplete="off" class="layui-input">
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">提成百分比</label>
		<div class="layui-input-block">
			<input type="text" name="points" value="<{$agent_info.points|default:''}>" onkeyup="this.value=this.value.replace(/[^0-9]/g,'')" onafterpaste="this.value=this.value.replace(/[^0-9]/g,'')" maxlength="2" autocomplete="off" class="layui-input">
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">区域</label>
		<div class="layui-input-inline">
			<select name="province_code" id="province" lay-filter="province" lay-verify="required">
				<option value="">请选择省</option>
				<{foreach from=$province_list item=item }>
				<option value="<{$item['area_code']}>" <{if isset($agent_info) && $agent_info['province_code']==$item['area_code'] }>selected<{/if}> ><{$item['area_name']}></option>
				<{/foreach}>
			</select>
		</div>
	   
		<div class="layui-input-inline">
			<select name="city_code" id="city" lay-filter="city" lay-verify="required">
				<option value="">请选择市</option>
				<{if isset($city_list)}>
				<{foreach from=$city_list item=item }>
				<option value="<{$item['area_code']}>" <{if isset($agent_info) && $agent_info['city_code']==$item['area_code'] }>selected<{/if}> ><{$item['area_name']}></option>
				<{/foreach}>
				<{/if}>
			</select>
		</div>

		<div class="layui-input-inline">
			<select name="area_code" id="district" lay-filter="district" lay-verify="required">
				<option value="">请选择区</option>
				<{if isset($area_list)}>
				<{foreach from=$area_list item=item }>
				<option value="<{$item['area_code']}>" <{if isset($agent_info) && $agent_info['area_code']==$item['area_code'] }>selected<{/if}> ><{$item['area_name']}></option>
				<{/foreach}>
				<{/if}>
			</select>
		</div>
		<input type="hidden" name="province_name" id="province_name" value="<{$agent_info['province_name']|default:''}>"/>
		<input type="hidden" name="city_name" id="city_name" value="<{$agent_info['city_name']|default:''}>"/>
		<input type="hidden" name="area_name" id="area_name" value="<{$agent_info['area_name']|default:''}>"/>
	</div>

	<div class="layui-form-item layui-form-text">
		<label class="layui-form-label">简介</label>
		<div class="layui-input-block">
			<textarea class="layui-textarea layui-hide editor" name="introduction" lay-verify="content" id="editor"><{$agent_info.introduction|default:""}></textarea>
		</div>
	</div>

	<div class="layui-input-block">
		<button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
		<button type="reset" class="layui-btn layui-btn-primary">重置</button>
	</div>
</form>
<{include file="public_html/footer.html"}>
<script>
	layui.use(['form', 'layedit', 'laydate'], function(){
		var form = layui.form();
		form.on('select(province)',function(data){
			var ii = layer.load();
			var province_code = data.value;
			$("#province_name").val($("#province option:selected").text())
			$("#city_name").val('');
			$("#area_name").val('');
			$("#city").html('<option value="">请选择城市</option>');
			$("#district").html('<option value="">请选择区域</option>');
			form.render('select');
			$.ajax({
				type: "GET",
				url: "/area/get_area_by_parent/"+province_code,
				dataType:"json",
				success: function(result){
					var html ='';
					$.each(result, function(i, obj) {
						html += '<option value="'+obj.area_code+'">'+obj.area_name+'</option>';
					});
					$("#city").append(html);
					form.render('select');
					layer.close(ii);
				}
			});
		});

		form.on('select(city)',function(data){
			var ii = layer.load();
			var city_code = data.value;
			$("#city_name").val($("#city option:selected").text())
			$("#area_name").val('');
			$("#district").html('<option value="">请选择区域</option>');
			form.render('select');
			$.ajax({
				type: "GET",
				url: "/area/get_area_by_parent/"+city_code,
				dataType:"json",
				success: function(result){
					var html ='';
					$.each(result, function(i, obj) {
						html += '<option value="'+obj.area_code+'">'+obj.area_name+'</option>';
					});
					$("#district").append(html);
					form.render('select');
					layer.close(ii);
				}
			});
		});

		form.on('select(district)',function(data){
			$("#area_name").val($("#district option:selected").text())
		});
	});
</script>